<template>
  <KiFormDialog :title="title" :show.sync="dialogVisible">
    <div v-if="info" class="text-18px">
      <p>{{ info.orderId }} {{ info.productName }}，数量{{ info.quantity }}</p>
      <p v-if="status == 13">拒绝预定进行退款？</p>
      <p v-if="status == 16">拒绝发货进行退款？</p>
      <p v-if="status == 8">确定进行手工退款？</p>
      <!-- 实物退款图片 -->
      <div
        v-if="
          info.businessTypeId == 5 &&
            info.refundApply &&
            info.refundApply.imageUrl
        "
      >
        <Imgpond v-model="info.refundApply.imageUrl" disabled />
      </div>
    </div>
    <el-input
      v-model="refuseReason"
      type="textarea"
      placeholder="请输入原因"
    ></el-input>
    <span slot="footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="confirm" :loading="inRequest">
        确定
      </el-button>
    </span>
  </KiFormDialog>
</template>
<script>
import API from './api'
export default {
  data () {
    return {
      dialogVisible: false,
      orderId: '',
      inRequest: false,
      info: null,
      status: '',
      refuseReason: '',
      businessTypeId: ''
    }
  },
  computed: {
    title () {
      if (this.businessTypeId == 4 && this.status != 8) {
        return '拒绝预定'
      } else if (this.businessTypeId == 5 && this.status != 8) {
        return '拒绝发货'
      }
    }
  },
  methods: {
    open (row) {
      this.info = {}
      this.refuseReason = ''
      this.orderId = row.orderId
      this.status = row.status
      this.businessTypeId = row.businessTypeId
      this.dialogVisible = true

      API.getOrderInfo({
        orderId: row.orderId
      }).then(({ data }) => {
        this.info = data
      })
    },
    confirm () {
      // 拒绝预订、拒绝发货 并退款
      if (!this.refuseReason) {
        this.$swal.error('请填入退款原因')
        return
      }
      this.inRequest = true
      API.refuseOrderRefund({
        orderId: this.orderId,
        refundDesc: this.refuseReason
      })
        .then(({ data }) => {
          this.$swal.success('操作成功')
          this.$emit('save')
          this.dialogVisible = false
          this.inRequest = false
        })
        .catch(() => {
          this.inRequest = false
        })
    }
  }
}
</script>
